home *** CD-ROM | disk | FTP | other *** search
- Path: uni-duisburg.de!news
- From: mauch@uni-duisburg.de (Michael Mauch)
- Newsgroups: comp.lang.c++
- Subject: Re: BC++ v4.02 : Huge memory model pointers
- Date: Sun, 28 Jan 1996 03:18:21 +0100
- Organization: Gesamthochschule Duisburg
- Distribution: world
- Message-ID: <3108c510.203552@news.uni-duisburg.de>
- References: <4cqt38$ce@hickory.soton.ac.uk>
- NNTP-Posting-Host: slip1.uni-duisburg.de
- X-Newsreader: Forte Agent .99c/16.141
-
- jcridge <jcridge@mail.soton.ac.uk> wrote:
-
- > If I compile and link using the huge memory model option in "Project Options", do I actually
- > need to use the 'huge' keyword anywhere in my program, or does the compiler/linker take care of
- > all this ? I would hope that the answer to the latter is 'yes', otherwise it seems I will have
- > to do alot of extra typing when swithcing memory models...
-
- I'm afraid the answer is 'yes'. Compile the following test program
- using the huge memory model:
-
- #include <stdio.h>
- #include <alloc.h>
-
- // #define DYNAMIC_TEST
- // #define huge
-
- int main(int argc, char* arg[])
- {
- unsigned long i;
- FILE* f;
-
- #ifdef DYNAMIC_TEST
- char huge* s;
- s=(char huge*)farcalloc(200000UL,1);
- #else
- static char huge s[200000UL];
- #endif
-
- f=fopen("hugeary.ary","wb");
- for(i=0;i<200000UL;i++)
- fprintf(f,"%c",s[i]); /* printing 200000 00's */
- fclose(f);
-
- for(i=0;i<200000UL;i++)
- s[i]=(char)((i%10UL)+'0'); /* setting up the array to s.th.*/
- s[200000UL-1]='\0'; /* setting the end of string marker */
-
- f=fopen("hugeary.ptr","wb");
- {
- char huge* p;
- for(p=s;*p;p++)
- fprintf(f,"%c",*p); /* printing the array (199999 bytes) */
- /*
- works ok with BC++ 3.1;
- with BC++ 4.01, it works only if 's' is on the heap
- (i.e. DYNAMIC_TEST is #define'd)
- - so much about compiler "upgrades"
- */
- }
- fclose(f);
-
- f=fopen("hugeary.str","wb");
- fprintf(f,"%Fs",s); /* this one won't work, not even with "%Fs" */
- fclose(f);
- }
-
- This program is supposed to write three files, each one about 200KB in
- size. Try it and #define "huge" and/or "DYNAMIC_TEST".
-
- So the point is: you have to use "huge" for each array larger than 64K
- and for each pointer that could point to something larger than 64K -
- and even then you can't be sure. The run-time library does not support
- huge arrays/pointers, neither.
-
- > Either way, does anyone know of any reason why a call to 'getch()' might crash the system under
- > the huge memory model option ?
-
- No, sorry.
-
- Regards...
- Michael
-